using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using DevComponents.DotNetBar;

using Resources = Pg.BioMedics.RatObserver.Gui.Properties.Resources;

namespace Pg.BioMedics.RatObserver.Gui
{
    public partial class PackageBrowserForm : Office2007Form
    {
        #region Fields

        private Packaging.VideoInfo _selectedVideoInfo;

        #endregion

        #region Constructors

        public PackageBrowserForm()
        {
            InitializeComponent();
        }

        #endregion

        #region Properties

        internal Packaging.VideoInfo SelectedVideoInfo
        {
            get
            {
                return _selectedVideoInfo;
            }
        }

        #endregion

        #region Methods

        internal DialogResult ShowDialog(IList<Packaging.VideoInfo> videoInfos, IWin32Window owner)
        {
            InitializeBrowser(videoInfos);
            return ShowDialog(owner);
        }

        #endregion

        #region Event handlers

        private void VideoInfoButtonItem_Click(object sender, EventArgs e)
        {
            ButtonItem buttonItem = (ButtonItem)sender;
            buttonItem.Checked = true;
            _selectedVideoInfo = (Packaging.VideoInfo)buttonItem.Tag;

            selectButton.Enabled = true;
        }

        private void VideoInfoButtonItem_DoubleClick(object sender, EventArgs e)
        {
            ButtonItem buttonItem = (ButtonItem)sender;
            _selectedVideoInfo = (Packaging.VideoInfo)buttonItem.Tag;

            DialogResult = DialogResult.OK;
            Close();
        }  

        private void SelectButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            Close();
        }

        #endregion

        #region Support methods

        private void InitializeBrowser(IList<Packaging.VideoInfo> videoInfos)
        {
            foreach (Packaging.VideoInfo videoInfo in videoInfos)
            {
                ButtonItem videoInfoButtonItem = new ButtonItem();
                videoInfoButtonItem.Text = String.Format("{0} {1} [{2}]", videoInfo.Date.ToString(), videoInfo.Title, videoInfo.Id.ToString());
                videoInfoButtonItem.ButtonStyle = eButtonStyle.ImageAndText;
                videoInfoButtonItem.Image = Resources.folder_video;
                videoInfoButtonItem.OptionGroup = "selection";
                videoInfoButtonItem.Click += new EventHandler(VideoInfoButtonItem_Click);
                videoInfoButtonItem.DoubleClick += new EventHandler(VideoInfoButtonItem_DoubleClick);
                videoInfoButtonItem.Tag = videoInfo;

                videosItemPanel.Items.Add(videoInfoButtonItem);
            }
        }             

        #endregion        
    }
}